<template>
  <div class="search-container">
    <form style="position:fixed;top:0;z-index:99;width:100%" action="/">
      <van-search
        background="#fff"
        v-model.trim="value"
        show-action
        placeholder="请输入搜索关键词"
        @search="onSearch"
        @cancel="onCancel"
      />
    </form>
    <span v-if="searchFlag">热门搜索</span>
    <!-- <span v-else> {{ '共' + length + '条数据' }}</span> -->

    <!-- 搜索结果 -->
    <search-result
      ref="child"
      :value="value"
      v-if="!searchFlag"
    ></search-result>
   
  </div>
</template>

<script>
import searchResult from './components/searchResults'
import { Toast } from 'vant'
//  _   {deepclone:function(){}}
// import { setItem, getItem, removeItem } from "@/utlis/storage";
export default {
  data() {
    return {
      value: '',
      searchFlag: true,
      length: '',
    }
  },
  methods: {
    onSearch(val) {
      console.log(val)
      this.searchFlag = false
      //用v-if的组件
      this.$nextTick(() => {
        this.$refs.child.getlist1(val)
        console.log(val)
      })
    },
    onCancel() {
      this.$router.back()
    },
    //更改总条数
    countAll(val) {
      console.log(val, 'asdad')
      this.length = val
    },
  },
  components: {
    searchResult,
  },
}
</script>
<style scoped lang="scss">
.search-container {
  padding-top: 120px;
}
</style>
